import jsonpath
import requests
import csv

url = 'https://bangumi.bilibili.com/api/timeline_v2_global?'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
    'Cookie': 'buvid3=A6615B68-6A4C-AA79-90D9-181D99BF6B8467485infoc; _uuid=5738D288-B63C-17D2-C886-0159521ED2BB68495infoc; CURRENT_FNVAL=80; blackside_state=1; bsource=search_baidu; PVID=1'
}
r = requests.get(url=url, headers=headers)
json_r = r.json()
title_name = jsonpath.jsonpath(json_r, '$.result..title')
time = jsonpath.jsonpath(json_r, '$.result..lastupdate_at')
csv_headers = ['名字', '时间']
g = open('./番剧.csv', 'w', encoding='utf-8')
g_csv = csv.writer(g)
g_csv.writerow(csv_headers)
for i in range(82):
    info = title_name[i], time[i]
    g_csv.writerow(info)
